#include "rpi_i2c.cpp"
#include "rpi_ms5611.cpp"
#include "bw_spi_8bit.cpp"

int main(int argc, char *argv[])
{
char line1_buf[16];
char line2_buf[16];
const char *device = "/dev/spidev0.1";
bw_spi_8bit  bwd(device,0x82,0x00,0x0);
bwd.lcd_clear();
bwd.lcd_setText("Hello world",11);
bwd.lcd_setPos(1,0);
bwd.lcd_setText("Thank You World",15);

//define MS5611 sensor
ms5611 barometric_sensor;
//take 5 measurements and average 
barometric_sensor.measureAvg(5);

double kHeight =99;
if (argc > 1) {
kHeight = atof(argv[1]);
}/*else{

}*/
barometric_sensor.knownHeight(kHeight);
while (1) {

barometric_sensor.measureAvg(5);
//print measure Temperature Pressure
//
int sz1 = sprintf(line1_buf,"T:%2.2f P:%4.2f",barometric_sensor.temperature(),barometric_sensor.pressure());
printf("%s\n",line1_buf);
bwd.lcd_clear();
bwd.lcd_setPos(0,0);
bwd.lcd_setText(line1_buf,sz1);
bwd.lcd_setPos(1,0);

printf("Temperature:%f\nPressure:%f\nAltitude:%F\n",
barometric_sensor.temperature(),barometric_sensor.pressure(),
barometric_sensor.calcAltitude()
);

int sz2 = sprintf(line1_buf,"Alt:%3.4f",barometric_sensor.calcAltitude());
bwd.lcd_setText(line1_buf,sz2);
usleep (250000);
}
};

